package com.itqf.factory;

import java.io.IOException;
import java.util.Properties;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/9/27
 * @Time: 上午10:07
 */
public class MyObjectFactory {
    Properties  properties = new Properties();

    public  MyObjectFactory(){

    }

    public MyObjectFactory(String config){
        try {
            properties.load(MyObjectFactory.class.getClassLoader().getResourceAsStream(config));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //得到对象
    public   Object getBean(String  beanName) throws  Exception{
        String classPath = properties.getProperty(beanName);
        //productDao=com.itqf.dao.ProductDao
        if (classPath!=null){
            Class clazz = Class.forName(classPath);

            return  clazz.newInstance();

        }

        return null;

    }




}
